home *** CD-ROM | disk | FTP | other *** search
/ Sky at Night 2007 June / SAN CD 6-2007 CD-ROM 25.iso / pc / Software / AstroGrav_Win / Java / jre1.6.0 / lib / rt.jar / sun / print / ServiceDialog$PrintServicePanel.class (.txt) < prev    next >
Encoding:
Java Class File  |  2006-11-29  |  6.5 KB  |  222 lines

  1. package sun.print;
  2.  
  3. import java.awt.Component;
  4. import java.awt.GridBagConstraints;
  5. import java.awt.GridBagLayout;
  6. import java.awt.event.ActionEvent;
  7. import java.awt.event.ActionListener;
  8. import java.awt.event.ItemEvent;
  9. import java.awt.event.ItemListener;
  10. import java.io.FilePermission;
  11. import java.net.URI;
  12. import java.net.URISyntaxException;
  13. import javax.print.ServiceUIFactory;
  14. import javax.print.attribute.PrintServiceAttribute;
  15. import javax.print.attribute.standard.Destination;
  16. import javax.print.attribute.standard.PrinterInfo;
  17. import javax.print.attribute.standard.PrinterIsAcceptingJobs;
  18. import javax.print.attribute.standard.PrinterMakeAndModel;
  19. import javax.swing.BorderFactory;
  20. import javax.swing.JButton;
  21. import javax.swing.JCheckBox;
  22. import javax.swing.JComboBox;
  23. import javax.swing.JDialog;
  24. import javax.swing.JLabel;
  25. import javax.swing.JPanel;
  26. import javax.swing.event.PopupMenuEvent;
  27. import javax.swing.event.PopupMenuListener;
  28.  
  29. class ServiceDialog$PrintServicePanel extends JPanel implements ActionListener, ItemListener, PopupMenuListener {
  30.    private final String strTitle;
  31.    private FilePermission printToFilePermission;
  32.    private JButton btnProperties;
  33.    private JCheckBox cbPrintToFile;
  34.    private JComboBox cbName;
  35.    private JLabel lblType;
  36.    private JLabel lblStatus;
  37.    private JLabel lblInfo;
  38.    private ServiceUIFactory uiFactory;
  39.    private boolean changedService;
  40.    private boolean filePermission;
  41.    // $FF: synthetic field
  42.    final ServiceDialog this$0;
  43.  
  44.    public ServiceDialog$PrintServicePanel(ServiceDialog var1) {
  45.       this.this$0 = var1;
  46.       this.strTitle = ServiceDialog.getMsg("border.printservice");
  47.       this.changedService = false;
  48.       this.uiFactory = ServiceDialog.access$400(var1).getServiceUIFactory();
  49.       GridBagLayout var2 = new GridBagLayout();
  50.       GridBagConstraints var3 = new GridBagConstraints();
  51.       this.setLayout(var2);
  52.       this.setBorder(BorderFactory.createTitledBorder(this.strTitle));
  53.       String[] var4 = new String[ServiceDialog.access$500(var1).length];
  54.  
  55.       for(int var5 = 0; var5 < var4.length; ++var5) {
  56.          var4[var5] = ServiceDialog.access$500(var1)[var5].getName();
  57.       }
  58.  
  59.       this.cbName = new JComboBox(var4);
  60.       this.cbName.setSelectedIndex(ServiceDialog.access$600(var1));
  61.       this.cbName.addItemListener(this);
  62.       this.cbName.addPopupMenuListener(this);
  63.       var3.fill = 1;
  64.       var3.insets = ServiceDialog.access$700();
  65.       var3.weightx = (double)0.0F;
  66.       JLabel var6 = new JLabel(ServiceDialog.getMsg("label.psname"), 11);
  67.       var6.setDisplayedMnemonic(ServiceDialog.access$800("label.psname"));
  68.       var6.setLabelFor(this.cbName);
  69.       ServiceDialog.access$300(var6, this, var2, var3);
  70.       var3.weightx = (double)1.0F;
  71.       var3.gridwidth = -1;
  72.       ServiceDialog.access$300(this.cbName, this, var2, var3);
  73.       var3.weightx = (double)0.0F;
  74.       var3.gridwidth = 0;
  75.       this.btnProperties = ServiceDialog.access$900("button.properties", this);
  76.       ServiceDialog.access$300(this.btnProperties, this, var2, var3);
  77.       var3.weighty = (double)1.0F;
  78.       this.lblStatus = this.addLabel(ServiceDialog.getMsg("label.status"), var2, var3);
  79.       this.lblStatus.setLabelFor((Component)null);
  80.       this.lblType = this.addLabel(ServiceDialog.getMsg("label.pstype"), var2, var3);
  81.       this.lblType.setLabelFor((Component)null);
  82.       var3.gridwidth = 1;
  83.       ServiceDialog.access$300(new JLabel(ServiceDialog.getMsg("label.info"), 11), this, var2, var3);
  84.       var3.gridwidth = -1;
  85.       this.lblInfo = new JLabel();
  86.       this.lblInfo.setLabelFor((Component)null);
  87.       ServiceDialog.access$300(this.lblInfo, this, var2, var3);
  88.       var3.gridwidth = 0;
  89.       this.cbPrintToFile = ServiceDialog.access$1000("checkbox.printtofile", this);
  90.       ServiceDialog.access$300(this.cbPrintToFile, this, var2, var3);
  91.       this.filePermission = this.allowedToPrintToFile();
  92.    }
  93.  
  94.    public boolean isPrintToFileSelected() {
  95.       return this.cbPrintToFile.isSelected();
  96.    }
  97.  
  98.    private JLabel addLabel(String var1, GridBagLayout var2, GridBagConstraints var3) {
  99.       var3.gridwidth = 1;
  100.       ServiceDialog.access$300(new JLabel(var1, 11), this, var2, var3);
  101.       var3.gridwidth = 0;
  102.       JLabel var4 = new JLabel();
  103.       ServiceDialog.access$300(var4, this, var2, var3);
  104.       return var4;
  105.    }
  106.  
  107.    public void actionPerformed(ActionEvent var1) {
  108.       Object var2 = var1.getSource();
  109.       if (var2 == this.btnProperties && this.uiFactory != null) {
  110.          JDialog var3 = (JDialog)this.uiFactory.getUI(3, "javax.swing.JDialog");
  111.          if (var3 != null) {
  112.             var3.show();
  113.          } else {
  114.             this.btnProperties.setEnabled(false);
  115.          }
  116.       }
  117.  
  118.    }
  119.  
  120.    public void itemStateChanged(ItemEvent var1) {
  121.       if (var1.getStateChange() == 1) {
  122.          int var2 = this.cbName.getSelectedIndex();
  123.          if (var2 >= 0 && var2 < ServiceDialog.access$500(this.this$0).length && !ServiceDialog.access$500(this.this$0)[var2].equals(ServiceDialog.access$400(this.this$0))) {
  124.             ServiceDialog.access$402(this.this$0, ServiceDialog.access$500(this.this$0)[var2]);
  125.             this.uiFactory = ServiceDialog.access$400(this.this$0).getServiceUIFactory();
  126.             this.changedService = true;
  127.             Destination var3 = (Destination)ServiceDialog.access$1100(this.this$0).get(Destination.class);
  128.             if ((var3 != null || this.isPrintToFileSelected()) && ServiceDialog.access$400(this.this$0).isAttributeCategorySupported(Destination.class)) {
  129.                if (var3 != null) {
  130.                   ServiceDialog.access$1200(this.this$0).add(var3);
  131.                } else {
  132.                   var3 = (Destination)ServiceDialog.access$400(this.this$0).getDefaultAttributeValue(Destination.class);
  133.                   if (var3 == null) {
  134.                      try {
  135.                         var3 = new Destination(new URI("file:out.prn"));
  136.                      } catch (URISyntaxException var5) {
  137.                      }
  138.                   }
  139.  
  140.                   if (var3 != null) {
  141.                      ServiceDialog.access$1200(this.this$0).add(var3);
  142.                   }
  143.                }
  144.             } else {
  145.                ServiceDialog.access$1200(this.this$0).remove(Destination.class);
  146.             }
  147.          }
  148.       }
  149.  
  150.    }
  151.  
  152.    public void popupMenuWillBecomeVisible(PopupMenuEvent var1) {
  153.       this.changedService = false;
  154.    }
  155.  
  156.    public void popupMenuWillBecomeInvisible(PopupMenuEvent var1) {
  157.       if (this.changedService) {
  158.          this.changedService = false;
  159.          ServiceDialog.access$1300(this.this$0);
  160.       }
  161.  
  162.    }
  163.  
  164.    public void popupMenuCanceled(PopupMenuEvent var1) {
  165.    }
  166.  
  167.    private boolean allowedToPrintToFile() {
  168.       try {
  169.          this.throwPrintToFile();
  170.          return true;
  171.       } catch (SecurityException var2) {
  172.          return false;
  173.       }
  174.    }
  175.  
  176.    private void throwPrintToFile() {
  177.       SecurityManager var1 = System.getSecurityManager();
  178.       if (var1 != null) {
  179.          if (this.printToFilePermission == null) {
  180.             this.printToFilePermission = new FilePermission("<<ALL FILES>>", "read,write");
  181.          }
  182.  
  183.          var1.checkPermission(this.printToFilePermission);
  184.       }
  185.  
  186.    }
  187.  
  188.    public void updateInfo() {
  189.       Class var1 = Destination.class;
  190.       boolean var2 = false;
  191.       boolean var3 = false;
  192.       boolean var4 = this.filePermission ? this.allowedToPrintToFile() : false;
  193.       if (ServiceDialog.access$400(this.this$0).isAttributeCategorySupported(var1)) {
  194.          var2 = true;
  195.       }
  196.  
  197.       Destination var5 = (Destination)ServiceDialog.access$1200(this.this$0).get(var1);
  198.       if (var5 != null) {
  199.          var3 = true;
  200.       }
  201.  
  202.       this.cbPrintToFile.setEnabled(var2 && var4);
  203.       this.cbPrintToFile.setSelected(var3 && var4 && var2);
  204.       PrintServiceAttribute var6 = ServiceDialog.access$400(this.this$0).getAttribute(PrinterMakeAndModel.class);
  205.       if (var6 != null) {
  206.          this.lblType.setText(var6.toString());
  207.       }
  208.  
  209.       PrintServiceAttribute var7 = ServiceDialog.access$400(this.this$0).getAttribute(PrinterIsAcceptingJobs.class);
  210.       if (var7 != null) {
  211.          this.lblStatus.setText(ServiceDialog.getMsg(var7.toString()));
  212.       }
  213.  
  214.       PrintServiceAttribute var8 = ServiceDialog.access$400(this.this$0).getAttribute(PrinterInfo.class);
  215.       if (var8 != null) {
  216.          this.lblInfo.setText(var8.toString());
  217.       }
  218.  
  219.       this.btnProperties.setEnabled(this.uiFactory != null);
  220.    }
  221. }
  222.